package com.controller;

import com.entity.User;
import com.service.impl.UserServiceimpl;
import com.utlils.DBUtlils;
import com.utlils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 更新用户数据
 */
@WebServlet("/UpDateUser")
public class UpDateUserController extends HttpServlet {
    UserServiceimpl service=new UserServiceimpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String rte = req.getParameter("id");
        boolean save=false;
        int id = Integer.parseInt(rte);
        String name = req.getParameter("name");
        String password = req.getParameter("password");
        String phone = req.getParameter("phone");
        String address = req.getParameter("address");
        String ide = req.getParameter("isdelete");
        int i = Integer.parseInt(ide);
        User user=new User(id,name,password,address,phone,i);
        Integer integer = service.UpDateUser(user);
        if(integer>0){
            save=true;
        }
        ResponseUtils.responseToJson(resp,save);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

}
